import configparser

# print(read_init.get('login_element','username'))
class Read_Init:
    def __init__(self,file_path=None):
        if file_path==None:
            self.file_path='/Users/chengyanan/PycharmProjects/kuai8_appium/config/Local_element.ini'
        else:
            self.file_path=file_path
        self.data=self.read_init()

    def read_init(self):
        read_init = configparser.ConfigParser()
        read_init.read(self.file_path)
        return read_init

    #通过参数key获取对应的value
    def get_value(self,key,section=None):
        if section==None:
            section='login_element'
        try:
            value=self.data.get(section,key)
        except:
            print('没有拿到ini文件的value值')
            value=None
        return value


if __name__ == '__main__':
    read_ini=Read_Init()
    print(read_ini.get_value('pass','course_element'))#取ini文件的第二组的元素
    print(read_ini.get_value('username'))#取ini文件的第一组的元素